clear all
cd "I:\workdata\706727\Build\Data"
use psychighfreq_AllAges_YearCollapse

gen sev=(firstpsykhosp==1 | firstpsychiatry==1 | firstsui==1)

keep pnr year minagec maxagec sev
keep if inrange(year,2000,2011)
gen age =floor(minagec)
keep if inrange(age,10,52) 

preserve
keep pnr year
duplicates drop

export sasxport5 MLSevpnrs, replace rename

restore

preserve
keep pnr year 
duplicates drop

save MLSevfull, replace

restore


*** Training data **
keep if inrange(year,2000,2007)

preserve
set seed 112
cap drop rand
gen rand=runiform()
sum sev
local R=r(mean)/(1-r(mean))
keep if inrange(rand,0,1*`R') | sev==1
drop rand
/* Mean =  .0197303 */

keep pnr year sev 

save MLSevSasTC, replace 
restore
